﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.Linq.Expressions;
using System.Reflection;
using System.Threading;
using EntModApp.EntServices.Presentation;

namespace EntModApp.EntServices
{
  [Serializable]
  public abstract class SyncNotifyObject : NotifyObject
  {
    protected override void TriggerPropertyChanged(PropertyChangedEventArgs args)
    {
      Send(() => base.TriggerPropertyChanged(args));
    }

    protected override void TriggerPropertyChainChanged(PropertyChainChangedEventArgs args)
    {
      Send(() => base.TriggerPropertyChainChanged(args));
    }

    protected void Send(Action<object> action, object state)
    {
      GlobalSynchronizationContext.Current.Send(o => action(o), state);
    }

    protected void Send(Action action)
    {
      GlobalSynchronizationContext.Current.Send(_ => action(), null);
    }

    protected void Post(Action<object> action, object state)
    {
      GlobalSynchronizationContext.Current.Post(o => action(o), state);
    }

    protected void Post(Action action)
    {
      GlobalSynchronizationContext.Current.Post(_ => action(), null);
    }
  }
}
